import { request } from '../utils/request';
import type {
    SaScanLog,
    SaReportRecord,
    SaScanDeployLog,
    SaReportAnaTask,
    SaScanLogQueryParams,
    SaReportRecordQueryParams,
    SaScanDeployLogQueryParams,
    SaReportAnaTaskQueryParams,
    PageResult,
    ApiResponse
} from '../pages/SaManagement/ScanManagement/types';

/**
 * 查询SA扫描日志（分页）
 * @param params 查询参数
 * @returns 分页结果
 */
export async function fetchScanLogList(params: SaScanLogQueryParams): Promise<PageResult<SaScanLog>> {
    const response: ApiResponse<PageResult<SaScanLog>> = await request({
        url: '/sa/scanLog/pageQuery',
        method: 'post',
        data: params
    });

    if (response.code === 200) {
        return response.data;
    }
    throw new Error(response.message || '查询扫描日志失败');
}

/**
 * 查询SA扫描记录（分页）
 * @param params 查询参数
 * @returns 分页结果
 */
export async function fetchReportRecordList(params: SaReportRecordQueryParams): Promise<PageResult<SaReportRecord>> {
    const response: ApiResponse<PageResult<SaReportRecord>> = await request({
        url: '/sa/record/pageQuery',
        method: 'post',
        data: params
    });

    if (response.code === 200) {
        return response.data;
    }
    throw new Error(response.message || '查询扫描记录失败');
}

/**
 * 查询SA部署日志（分页）
 * @param params 查询参数
 * @returns 分页结果
 */
export async function fetchDeployLogList(params: SaScanDeployLogQueryParams): Promise<PageResult<SaScanDeployLog>> {
    const response: ApiResponse<PageResult<SaScanDeployLog>> = await request({
        url: '/sa/deployLog/pageQuery',
        method: 'post',
        data: params
    });

    if (response.code === 200) {
        return response.data;
    }
    throw new Error(response.message || '查询部署日志失败');
}

/**
 * 查询SA分析任务（分页）
 * @param params 查询参数
 * @returns 分页结果
 */
export async function fetchAnaTaskList(params: SaReportAnaTaskQueryParams): Promise<PageResult<SaReportAnaTask>> {
    const response: ApiResponse<PageResult<SaReportAnaTask>> = await request({
        url: '/sa/anaTask/pageQuery',
        method: 'post',
        data: params
    });

    if (response.code === 200) {
        return response.data;
    }
    throw new Error(response.message || '查询分析任务失败');
}
